package com.yimu.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yimu.common.annotation.Log;
import com.yimu.common.enums.BusinessType;
import com.yimu.system.domain.Devices;
import com.yimu.system.service.IDevicesService;
import com.yimu.common.core.controller.BaseController;
import com.yimu.common.core.domain.AjaxResult;
import com.yimu.common.utils.poi.ExcelUtil;
import com.yimu.common.core.page.TableDataInfo;

/**
 * 终端列表Controller
 * 
 * @author Christine
 * @date 2020-08-26
 */
@Controller
@RequestMapping("/system/devices")
public class DevicesController extends BaseController
{
    private String prefix = "system/devices";

    @Autowired
    private IDevicesService devicesService;

    @RequiresPermissions("system:devices:view")
    @GetMapping()
    public String devices()
    {
        return prefix + "/devices";
    }

    /**
     * 查询终端列表列表
     */
    @RequiresPermissions("system:devices:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Devices devices)
    {
        startPage();
        List<Devices> list = devicesService.selectDevicesList(devices);
        return getDataTable(list);
    }

    /**
     * 导出终端列表列表
     */
    @RequiresPermissions("system:devices:export")
    @Log(title = "终端列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Devices devices)
    {
        List<Devices> list = devicesService.selectDevicesList(devices);
        ExcelUtil<Devices> util = new ExcelUtil<Devices>(Devices.class);
        return util.exportExcel(list, "devices");
    }

    /**
     * 新增终端列表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存终端列表
     */
    @RequiresPermissions("system:devices:add")
    @Log(title = "终端列表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Devices devices)
    {
        return toAjax(devicesService.insertDevices(devices));
    }

    /**
     * 修改终端列表
     */
    @GetMapping("/edit/{Id}")
    public String edit(@PathVariable("Id") Long Id, ModelMap mmap)
    {
        Devices devices = devicesService.selectDevicesById(Id);
        mmap.put("devices", devices);
        return prefix + "/edit";
    }

    /**
     * 修改保存终端列表
     */
    @RequiresPermissions("system:devices:edit")
    @Log(title = "终端列表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Devices devices)
    {
        return toAjax(devicesService.updateDevices(devices));
    }

    /**
     * 删除终端列表
     */
    @RequiresPermissions("system:devices:remove")
    @Log(title = "终端列表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(devicesService.deleteDevicesByIds(ids));
    }
}
